package com.cn.kabalifemerchants.ui.user.adapter;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cn.kabalifemerchants.R;
import com.cn.kabalifemerchants.ui.user.bean.CashListBean;
import com.cn.kabalifemerchants.ui.user.bean.ShouRuListBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;

import java.util.List;

/**
 * Created by 晓林 on 2020/10/21.
 * function:
 */
public class ShouRuAdapter extends BaseQuickAdapter<ShouRuListBean.ResultBean.DataBean, BaseViewHolder> {
    public ShouRuAdapter(int layoutResId, @Nullable List<ShouRuListBean.ResultBean.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ShouRuListBean.ResultBean.DataBean item) {
        helper.setText(R.id.tv_time, item.getCreated_at())
        ;
        TextView tvx = helper.getView(R.id.tv_nickname);
        String m = String.valueOf(item.getTotal_amount());
        String money = "消费" + m;
        String str = item.getNickname() + money + "购买" + item.getTitle() + "商品，共获得" + item.getMoney() + "元提成";
//        tvx.setText(str);

        int start = str.indexOf(money);
        int end = money.length() + item.getNickname().length();
        LoggerUtils.e("长度：" + start + "zzzz" + money.length() + "m" + m + "m的长度" + m.length());

        SpannableString spannableString = new SpannableString(str);
//        ClickableSpan clickableSpan1 = new ClickableSpan() {
//            @Override
//            public void onClick(View view) {
//            }
//
//            @Override
//            public void updateDrawState(@NonNull TextPaint ds) {
//                ds.setColor(ContextCompat.getColor(mContext, R.color.main_color));//设置颜色
//                ds.setUnderlineText(false);//去掉下划线
//            }
//        };
        //设置下划线文字
//        spannableString.setSpan(new UnderlineSpan(), start, end,  Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        //设置文字的前景色
        spannableString.setSpan(new ForegroundColorSpan(mContext.getResources().getColor(R.color.main_color)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvx.setText(spannableString);
    }
}
